Only avoid dev deps in `cargo install` and `cargo build --avoid-dev-deps`
authorXimin Luo <infinity0@pwned.gg>
Mon, 5 Feb 2018 15:15:13 +0000 (16:15 +0100)
committerXimin Luo <infinity0@pwned.gg>
Tue, 6 Feb 2018 00:35:20 +0000 (01:35 +0100)
src/bin/build.rs
src/cargo/core/workspace.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_install.rs

index 889052068e477e5cb4bfcfd295d37cd9eb04efed..9b576e922051429fcf3bc598aa58c69744713cf4 100644 (file)
@@ -12,6 +12,7 @@ pub struct Options {
     flag_features: Vec<String>,
     flag_all_features: bool,
     flag_no_default_features: bool,
+    flag_avoid_dev_deps: bool,
     flag_target: Option<String>,
     flag_manifest_path: Option<String>,
     flag_verbose: u32,
@@ -63,6 +64,7 @@ Options:
     --features FEATURES          Space-separated list of features to also build
     --all-features               Build all available features
     --no-default-features        Do not build the `default` feature
+    --avoid-dev-deps             Avoid installing dev-dependencies if possible
     --target TRIPLE              Build for the target triple
     --manifest-path PATH         Path to the manifest to compile
     -v, --verbose ...            Use verbose output (-vv very verbose/build.rs output)
@@ -98,7 +100,10 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult {
                      &options.flag_z)?;
 
     let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
-    let ws = Workspace::new(&root, config)?;
+    let mut ws = Workspace::new(&root, config)?;
+    if options.flag_avoid_dev_deps {
+        ws.set_require_optional_deps(false);
+    }
 
     let spec = Packages::from_flags(options.flag_all,
                                     &options.flag_exclude,
index 5d21dd8d41a6919499b8f916af8c302e258e73be..00e93a92743636228a3f613bf03df3418e1e48e8 100644 (file)
@@ -300,6 +300,11 @@ impl<'cfg> Workspace<'cfg> {
         self.require_optional_deps
     }
 
+    pub fn set_require_optional_deps<'a>(&'a mut self, require_optional_deps: bool) -> &mut Workspace<'cfg> {
+        self.require_optional_deps = require_optional_deps;
+        self
+    }
+
     /// Finds the root of a workspace for the crate whose manifest is located
     /// at `manifest_path`.
     ///
index a212a64552ee38c7f2c9372c785ef45efd5187e6..bf905c3afd1a35be38a99eb44a16725a54b7f7b9 100644 (file)
@@ -228,7 +228,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
     let specs = spec.into_package_id_specs(ws)?;
     let features = Method::split_features(features);
     let method = Method::Required {
-        dev_deps: filter.need_dev_deps(),
+        dev_deps: ws.require_optional_deps() || filter.need_dev_deps(),
         features: &features,
         all_features,
         uses_default_features: !no_default_features,
index c85923e453b2d46ca2e6a91bec3c4324aa7330b7..703a96da44f53fff56094549aac7e86ddf9700f1 100644 (file)
@@ -175,7 +175,11 @@ fn install_one(root: &Filesystem,
 
     let ws = match overidden_target_dir {
         Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
-        None => Workspace::new(pkg.manifest_path(), config)?,
+        None => {
+            let mut ws = Workspace::new(pkg.manifest_path(), config)?;
+            ws.set_require_optional_deps(false);
+            ws
+        }
     };
     let pkg = ws.current()?;